package algorithm.tree;

import algorithm.model.TreeNode;

/**
 * https://leetcode.com/problems/maximum-depth-of-binary-tree/
 * Easy
 * 求树的最大深度
 * 深度优先，递归找到所有叶子的深度。即是最大深度。
 * Created by yzy on 2021-03-16 20:13
 */
public class MaxDepthTree {

    public int maxDepth(TreeNode root) {
        if(root==null) return 0;
        return Math.max(maxNodeDepth(root.left, 1), maxNodeDepth(root.right, 1));
    }

    public int maxNodeDepth(TreeNode node, int depth){
        if(node == null) return depth;
        return Math.max(maxNodeDepth(node.left, depth+1), maxNodeDepth(node.right, depth+1));
    }
}
